package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baor.dao.WithdrawalsDao;
import com.baor.domain.conf.SeparateConf;
import com.baor.domain.conf.WithdrawalsConf;
import com.baor.service.WithdrawalsService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WithdrawalsServiceImpl implements WithdrawalsService {

    @Autowired
    private WithdrawalsDao withdrawalsDao;

    @Override
    public AjaxResult<?> withdrawalsInfo(WithdrawalsConf withdrawalsConf) {
        return AjaxResult.success(withdrawalsDao.selectById(withdrawalsConf.getSiteId()));
    }

    @Override
    public AjaxResult<?> updateWithdrawals(WithdrawalsConf withdrawalsConf) {
        LambdaQueryWrapper<WithdrawalsConf> queryWrapper = new LambdaQueryWrapper<>();
        List<WithdrawalsConf> list = withdrawalsDao.selectList(null);
        long count = list.stream().filter(x -> x.getSiteId().equals(withdrawalsConf.getSiteId())).count();
        if (count > 0) {
            return AjaxResult.success(withdrawalsDao.updateById(withdrawalsConf));
        }else {
            return AjaxResult.success(withdrawalsDao.insert(withdrawalsConf));
        }
    }
}
